package net.learn2develop.view;

//import java.io.InputStream;
//import java.net.URL;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.drawable.Drawable;

import android.widget.Toast;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;


public class Markers extends ItemizedOverlay<OverlayItem>{

	Context mContext;
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	
	public Markers(Drawable defaultMarker) {
		  super(boundCenterBottom(defaultMarker));
		}
	
	public void addOverlay(OverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	}
	
	@Override
	protected OverlayItem  createItem(int i) {
	  return mOverlays.get(i);
	}
	
	@Override
	public int size() {
	  return mOverlays.size();
	}
	
	public Markers(Drawable defaultMarker, Context context) {
		  super(boundCenterBottom(defaultMarker));
		  mContext = context;
		}
	
	@Override
	protected boolean onTap(int index) {
		
	  OverlayItem item = mOverlays.get(index);
	  Toast toast = Toast.makeText(mContext, item.getTitle(),Toast.LENGTH_SHORT);
//	  toast.setMargin(2.5f, 2.75f);
//	  LinearLayout toastView = (LinearLayout) toast.getView();
//	  ImageView image = new ImageView(mContext);
//	  image.setImageResource(R.drawable.icon);
//	  Drawable drawable = LoadImageFromWebOperations("http://www.fastfoodfactory.com/wp-content/uploads/2009/05/mc-donalds-logo.png");
//	  image.setImageDrawable(drawable);
//	  toastView.addView(image, 0);
	  toast.show();
	  return true;
	}
	
//	private Drawable LoadImageFromWebOperations(String url)
//	   {
//	        try
//	        {
//	            InputStream is = (InputStream) new URL(url).getContent();
//	            Drawable d = Drawable.createFromStream(is, "src name");
//	            return d;
//	        }catch (Exception e) {
//	            System.out.println("Exc="+e);
//	            return null;
//	        }
//	    }
}
